﻿using System;
using System.Collections.Generic;
using System.Web;
using OneMG.Phoenix.Service.Model;
using OneMG.Phoenix.Service.Contracts;
using OneMG.Phoenix.Service;
using OneMG.Phoenix.Kernel.Util;

namespace OneMG.Phoenix.AdminSite.Views.Category
{

    public class Save : IHttpHandler
    {
        ICategoryService ICategory = new CategoryService();

        public void ProcessRequest(HttpContext context)
        {
            CategoryModel model = new CategoryModel()
            {
                CategoryName=context.Request.Form["txtCategoryName"],
                CateSort= int.Parse(context.Request.Form["txtSort"]),
                CateStatus=1,
                CateAleph="",
                CreateTime=DateTime.Now,
                CreateUser=1,
                IsLeaf=false,
                LinkUrl="",
                ParentID = int.Parse(context.Request.Form["sltParentCategoryID"]),
                Photo="",
                UpdateTime=DateTime.Now,
                UpdateUser=1
            };


             string action = "";
           
                if (string.IsNullOrEmpty(context.Request.Form["hdCategoryID"]))
                {
                    ICategory.AddCategory(model);
                    action = "新增操作成功";
                }
                else
                {
                    model.CategoryID = int.Parse(context.Request.Form["hdCategoryID"]);
                    ICategory.UpdateByCategoryID(model);
                    action = "编辑操作成功";
                }
             JsonResult.Result(context, JsonMessageStatus.OK, action);
        }


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
